After we have tinkered with general plotting in R, and before we learn from other plotting methods using ggplot2, we now conclude our session with programmatically playing with plots. In the previous exercise, we had some repeated tasks to perform. Maybe we can find a more elegant way of creating multiple plots.
Make sure our GESIS Panel COVID-19 data are loaded:
library(dplyr)
library(haven)
gp_covid <-
read_sav(
"../data/ZA5667_v1-1-0.sav"
) %>%
sjlabelled::set_na(na = c(-1:-99, 97))
function (variable, data) and call the variable within the function with data[[variable]].
Pew, that was not about plotting but rather about programming (sorry!). But now you can use this function and include it in a loop!
par() before the loop to have all variables nicely plotted in one graph.
for() loop, which iterates over this character vector.
Before we later start with the other exercises, you may want to consider to clean your graphics device with dev.off()
dev.off()
## null device
## 1